/**
 * token操作封装
 *
 */

type Token = string;

/**
 * 获取缓存的token
 */
export function getToken() {
  const token = localStorage.getItem('token1');
  return token;
}

/**
 * 移除token
 */
export function removeToken() {
  localStorage.removeItem('token1');
}

/**
 * 缓存token
 * @param token token
 */
export function setToken(token: Token) {
  removeToken();
  localStorage.setItem('token1', token);
}

type Id = number;

/**
 * 获取缓存的id
 */
export function getId() {
  const id = localStorage.getItem('id');
  return Number(id);
}

/**
 * 移除id
 */
export function removeId() {
  localStorage.removeItem('id');
}

/**
 * 缓存id
 * @param token token
 */
export function setId(id: Id) {
  removeId();
  localStorage.setItem('id', String(id));
}

type Lock = boolean;

/**
 * 获取缓存的锁屏状态
 */
export function getLock() {
  const lock = localStorage.getItem('lock');

  if (!lock || lock === 'false') {
    return false;
  } else {
    return true;
  }
}

/**
 * 移除锁屏状态
 */
export function removeLock() {
  localStorage.removeItem('lock');
}

/**
 * 缓存锁屏状态
 * @param lock 锁屏状态
 */
export function setLock(lock: Lock) {
  removeLock();
  localStorage.setItem('lock', String(lock));
}

// 保存登录的密码作为锁屏解锁密码
type Pwd = string;

/**
 * 获取缓存的pwd
 */
export function getPwd() {
  const pwd = localStorage.getItem('pwd');
  return pwd;
}

/**
 * 移除pwd
 */
export function removePwd() {
  localStorage.removeItem('pwd');
}

/**
 * 缓存pwd
 * @param pwd 密码
 */
export function setPwd(pwd: Pwd) {
  removePwd();
  localStorage.setItem('pwd', String(pwd));
}
